import query from '@dfeidao/atom-nodejs/db/query';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../atom/config';

interface Message {
	productid: string;
	information_template_type: string;
	information_template_status: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string;
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {

	const { prepare, exec } = query(action_id, session_id, systemid);
	prepare('information_template', ["productid", "information_template_type", "information_template_title", "information_template_status", "information_template_content"], { productid: message.productid, information_template_type: '3', information_template_status: '1' }, 1, 1, [], []);
	const [data] = await exec();

	return {
		data
	};
}
